package com.sjk.flink.correct.rules;

import com.sjk.flink.correct.IfCorrectRule;

/**
 *
 */
public class TrueFalseRuler implements IfCorrectRule {

    private final static String TRUE_STRING = "1 true";

    private final static String FALSE_STRING = "0 false";

    @Override
    public String getName() {
        return "TrueFalse";
    }

    /**
     * 获得校准替换的值
     *
     * @param val 原始值
     * @return 校准值
     */
    @Override
    public Object transformValue(Object val) {
        //不转换
        if(val==null){
            return false;
        }
        String value = String.valueOf(val);
        if(value.isEmpty()){
            return false;
        }
        value = value.toLowerCase();
        if(TRUE_STRING.contains(value)){
            return true;
        }
        if(FALSE_STRING.contains(value)){
            return false;
        }
        //校准失败
        return val;
    }
}
